/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.upc.pc2.service;

import upc.com.pc2.Estudiante;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response;

/**
 *
 * @author Julio
 */
@Stateless
@Path("upc.com.pc2.estudiante")
public class EstudianteFacadeREST extends AbstractFacade<Estudiante> {
    @PersistenceContext(unitName = "PC2_JulioZevallosPU")
    private EntityManager em;

    public EstudianteFacadeREST() {
        super(Estudiante.class);
    }

    @GET
    @Path("GET/Estuduante")
    //@Override
    @Produces({"application/xml", "application/json"})
    public List<Estudiante> findAll() {
        return super.findAll();
    }

    @POST
    @Path("POST/Estudiante")
    //@Override
    @Consumes({"application/xml", "application/json"})
    public void create(Estudiante entity) {
        super.create(entity);
    }

    @GET
    @Path("Estudiante/{id}")
    @Produces({"application/xml", "application/json"})
    public Estudiante find(@PathParam("id") String id) {
        return super.find(id);
    }

    @PUT
    @Path("PUT/Estudiante/{id}")
    @Consumes({"application/xml", "application/json"})
    public void editEstudiante(Estudiante entity) {
        super.edit(entity);
    }
    
    @DELETE
    @Path("DELETE/Estudiante/{id}")
    public void removeEstudiante(@PathParam("id") String id) {
        super.remove(super.find(id));
    }
    
    @GET
    @Path("Query/{apellido}/{nombre}")
    @Produces({"application/xml", "application/json"})
    public List<Estudiante> consultaEstudiante(@PathParam("apellido") String apellido, @PathParam("nombre") String nombre) {
        Query q = em.createQuery("SELECT s FROM Estudiante s WHERE s.nombre = :nombre AND s.apellido = :apellido");
        q.setParameter("apellido", apellido);
        q.setParameter("nombre", nombre);
        return q.getResultList();
    }
    
    /*
    @PUT
    @Override
    @Consumes({"application/xml", "application/json"})
    public void edit(Estudiante entity) {
        super.edit(entity);
    }
    */

    /*
    @DELETE
    @Path("{id}")
    public void remove(@PathParam("id") String id) {
        super.remove(super.find(id));
    }
    */
    
    /*
    @GET
    @Path("{from}/{to}")
    @Produces({"application/xml", "application/json"})
    public List<Estudiante> findRange(@PathParam("from") Integer from, @PathParam("to") Integer to) {
        return super.findRange(new int[]{from, to});
    }
    */
       
    /*
    @GET
    @Path("count")
    @Produces("text/plain")
    public String countREST() {
        return String.valueOf(super.count());
    }
    */

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }
    
}